#include "adspage.h"
#include "ui_adspage.h"
#include "customwidget.h"

Adspage::Adspage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Adspage)
{
    ui->setupUi(this);
}

Adspage::~Adspage()
{
    delete ui;
}


void Adspage::removeItem(const QString &text) {

    for (int i = 0; i < ui->listWidget->count(); ++i) {
        auto item = ui->listWidget->item(i);
        auto itemWidget = dynamic_cast<CustomWidget*>(ui->listWidget->itemWidget(item));
        if (itemWidget->getText() == text){
            delete item;
            break;
        }
    }
}

void Adspage::on_addbutton_clicked()
{
    auto item = new QListWidgetItem();
    auto widget = new CustomWidget(this);
    widget->setText(QString("text"));

    item->setSizeHint(widget->sizeHint());

    ui->listWidget->addItem(item);
    ui->listWidget->setItemWidget(item, widget);
}

